<?php

//Get required classes
require_once ("Model/User.php");
require_once ("Model/UserHandler.php");
require_once ("Model/LoginHandler.php");
require_once ("view/NavigationView.php");
require_once ("Controller/LoginController.php");
require_once ("Controller/SignUpController.php");
require_once ("Controller/ShowUserController.php");
require_once ("Controller/IController.php");

class PageMasterController implements IController {

	private $DBConnection = null;
	private $DBPrefix = null;
	private $page = null;
	private $userHandler = null;
	private $loginHandler = null;

	public function __construct(DBConnection $a_dbconnection, $a_DBprefix) {
		$this -> DBConnection = $a_dbconnection;
		$this -> DBPrefix = $a_DBprefix;
		$this -> page = new Page();
		$this -> page -> title = "YAIC";
		$this -> userHandler = new UserHandler($this -> DBConnection, $this -> DBPrefix);
		$this -> loginHandler = new LoginHandler($this -> userHandler);
	}

	public function DoControll() {
		switch (NavigationView::getActiveController()) {
			case navigationView::login :
				$loginController = new LoginController($this -> loginHandler);
				$this -> page = $loginController -> doControll();
				break;
			case navigationView::signup :
				$signUpController = new SignUpController($this -> userHandler);
				$this -> page = $signUpController -> doControll();
				break;
			case navigationView::learnMore :
				$this -> page -> body .= NavigationView::generateAboutDiv();
				$this->page->title .= " | About";
				break;
			case NavigationView::showUserController :
				$showUserController = new ShowUserController($this -> userHandler, $this -> DBConnection, $this -> DBPrefix);
				$UserPage = $showUserController -> doControll($this -> loginHandler -> getLoggedInUser());
				$this -> page -> body .= $UserPage -> body;
				$this -> page -> title .= $UserPage -> title;
				break;
			default :
				$this -> page -> body .= NavigationView::generateJSSlider();
				break;
		}
		$this -> page -> menu = NavigationView::getMenu($this -> loginHandler -> getLoggedInUser());
		return $this -> page;
	}
}
